package pl.edu.agh.mwo.model;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Date;

public class CSVExporterUtils {
	public static void exportToCSV(String pathToExportTo) {

		try {
			// Create file
			FileWriter fstream = new FileWriter(pathToExportTo);
			BufferedWriter out = new BufferedWriter(fstream);
            
		//	KatalogDanych.addData(new UserProjectData("Piotr", "Luczynski", "Projekt1",new Date(),"Task1", 10));
		//	KatalogDanych.addData(new UserProjectData("Pawel", "Grudzien", "Projekt1",new Date(),"Task1", 10));
			
			ArrayList<UserData> daneUser = (ArrayList<UserData>) KatalogDanych
					.getUniqUsers();

			for (UserData user : daneUser) {
				out.append(user.getImie());
				out.append(" ");
				out.append(user.getNazwisko());
				out.append(";");
				//out.append("" + user.getGodziny());
				out.append(Integer.toString(user.getGodziny()));
				out.append(";");
				out.append("\r");
				out.append("\n");
			}
			out.close();
			fstream.close();

		} catch (Exception e) { // Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}		
	}
	
	public static void exportToCSVProj(String pathToExportTo) {

		try {
			// Create file
			FileWriter fstream = new FileWriter(pathToExportTo);
			BufferedWriter out = new BufferedWriter(fstream);
            
			
			ArrayList<ProjectData> daneProject = (ArrayList<ProjectData>) KatalogDanych.getUniqProject();

			for (ProjectData proj : daneProject) {
				out.append(proj.getProject());				
				out.append(";");
				out.append(Integer.toString(proj.getGodziny()));
				out.append(";");
				out.append("\r");
				out.append("\n");
			}
			out.close();
			fstream.close();

		} catch (Exception e) { // Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}		
	}
	
	
/*	public static void main(String[] args) {
		CSVExporterUtils.exportToCSV("C:/plik.csv");
	} */
}
